# -*- encoding=utf8 -*-
__author__ = "jwjwchen"
"""函数文件，不可更改"""

from airtest.core.api import *
import sys,os
sys.path.append(os.getcwd())
from bring_up_fish_config import *
#-----------------------------------------------------
def wait_for_appearance_and_click(object):
    object.wait_for_appearance()
    print ("找到元素，准备点击")
    object.click()
    print ("已点击")
        
def match_object_and_click(match_value,attr_type,object_list):
    '''
    match_value:匹配的值
    object_list:被匹配的poco元素对象列表
    attr_type:匹配的类型值
    '''
    count = len(object_list)
    for i in range(count):
        text_value = object_list[i].attr("text")
        if text_value:
            if match_value in text_value:
                print (object_list[i],text_value)
                object_list[i].click()
            
def click_element_list(object_list,click_max_times):
    '''
    object_list:被匹配的poco元素对象列表
    click_max_times:最多点击次数
    '''
    a=0
    count = len(object_list)
    for i in range(count):
        object_list[i].click()
        a+=1
        if a == click_max_times:
            break
            
def init_idle_fish(package_name):
    '''初始化app'''
    stop_app(package_name)
    sleep(5)
    start_app(package_name)
    
    
    
def choice_comment():
    '''随机选择comment类型的评论内容'''
    from random import choice
    comment_list = []
    for i in range(1,100):
        comment_num='comment'+'_%s'%i
        try:
            comment = globals()[comment_num]
        except:
            comment = None
        if comment:
            comment_list.append(comment)
    comment = choice(comment_list) 
    return comment


def if_exists_try_click(object):
    if object.exists():
        print ("页面存在,准备点击")
        object.click()

        
        
def auto_choice_rand_conment(comment_type):
    '''自动选择指定类型的内容'''
    from random import choice
    comment_list = []
    for i in range(1,100):
        comment_num=comment_type+'_%s'%i
        try:
            comment = globals()[comment_num]
        except:
            comment = None
        if comment:
            comment_list.append(comment)
    comment = choice(comment_list) 
    return comment



            
if __name__ ==  "__main__":
    pass

   
